@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

/* 主题颜色变量 */
:root {
    --gradient-start: #fde047;
    --gradient-mid: #f97316;
    --gradient-end: #ef4444;
    --font-family: 'Roboto', sans-serif;
    --sidebar-width: 260px;
}

body.dark-mode {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --highlight-bg-color: #333333;
    --text-color-primary: #e0e0e0;
    --text-color-secondary: #a5a5a5;
    --text-color-tertiary: #888;
    --border-color: #444;
    --input-bg-color: #252525;
    --input-hover-bg-color: #2a2a2a;
    --surface-border-color: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.37);
    --error-color: #ef4444;
}

body.light-mode {
    --bg-color: #f0f2f5;
    --surface-color: #ffffff;
    --highlight-bg-color: #e5e7eb;
    --text-color-primary: #1f2937;
    --text-color-secondary: #4b5563;
    --text-color-tertiary: #6b7280;
    --border-color: #d1d5db;
    --input-bg-color: #f3f4f6;
    --input-hover-bg-color: #e5e7eb;
    --surface-border-color: #e5e7eb;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --error-color: #dc2626;
}


body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color-primary);
    margin: 0;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

/* --- NEW STYLES START --- */

/* Sidebar Toggle Button */
#sidebar-toggle-btn {
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color-secondary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    z-index: 1001; /* Higher than sidebar */
    transition: background-color 0.3s, border-color 0.3s, color 0.3s, transform 0.3s;
}
#sidebar-toggle-btn:hover {
    background-color: var(--input-hover-bg-color);
}
#sidebar-toggle-btn svg {
    stroke: var(--text-color-secondary);
}

/* Sidebar Container */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--surface-color);
    border-right: 1px solid var(--surface-border-color);
    padding: 6rem 1rem 1rem;
    box-sizing: border-box;
    z-index: 1000;
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

#sidebar.sidebar-hidden {
    transform: translateX(-100%);
}

/* Main Content Wrapper */
#main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    box-sizing: border-box;
    transition: margin-left 0.3s ease-in-out, width 0.3s ease-in-out;
}

#sidebar.sidebar-hidden + #main-content {
    margin-left: 0;
    width: 100%;
}

/* --- NEW STYLES END --- */


/* 主题切换按钮样式 */
#theme-toggle-btn {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color-secondary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    z-index: 1000;
    transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}
#theme-toggle-btn:hover {
    background-color: var(--input-hover-bg-color);
}
#theme-toggle-btn svg {
    stroke: var(--text-color-secondary);
}
.light-mode .icon-sun, .dark-mode .icon-moon { display: block; }
.light-mode .icon-moon, .dark-mode .icon-sun { display: none; }


.title {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-top: 0;
    margin-bottom: 2rem; /* Increased margin to avoid overlap with controls */
}

/* 模型选择器样式 (MODIFIED) */
.model-selector-container {
    display: flex;
    flex-direction: column; /* Changed to column */
    gap: 0.5rem; /* Added gap between items */
    position: relative;
    /* Removed old horizontal styles */
}

.model-selector-container::before {
    content: '';
    position: absolute;
    /* MODIFIED for vertical layout */
    top: var(--highlight-top, 0px);
    left: 0px;
    width: 100%;
    height: var(--highlight-height, 0px);
    background-color: var(--highlight-bg-color);
    border-radius: 8px; /* Matched border-radius of cards */
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: top 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), height 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1;
}

.model-card {
    display: flex;
    justify-content: flex-start; /* Align text to left */
    align-items: center;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    z-index: 2;
    color: var(--text-color-secondary);
    transition: color 0.3s ease;
    border-radius: 8px; /* Unified border radius */
    background: none;
    border: none;
    margin: 0;
    width: 100%; /* Ensure full width */
    box-sizing: border-box;
}

.model-card.active {
    color: var(--text-color-primary);
}

.main-container {
    display: flex;
    gap: 2rem;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.controls-container, .result-container {
    flex: 1;
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--shadow-color);
    border: 1px solid var(--surface-border-color);
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, border-color 0.3s;
}

#openrouter-controls, #modelscope-controls {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.result-container {
    min-height: 600px;
}

h2 {
    color: var(--text-color-primary);
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1.25rem;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.api-key-section, .upload-section, .prompt-section {
    margin-bottom: 1.2rem;
}

.settings-section {
    margin-bottom: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.setting-item {
    display: flex;
    flex-direction: column;
}

.setting-item label {
    margin-bottom: 0.5rem;
    color: var(--text-color-secondary);
}

.param-note {
    font-size: 0.8rem;
    color: var(--text-color-tertiary);
    margin-left: 0.5rem;
}

.prompt-remark {
    font-size: 0.85rem;
    color: var(--text-color-secondary);
    font-weight: normal;
    margin-left: 0.75rem;
    min-height: 1.2em;
}

/* 新增的样式 */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
    background: var(--input-bg-color);
    cursor: pointer;
}

.upload-area:hover, .upload-area.drag-over {
    border-color: var(--gradient-mid);
    background: var(--input-hover-bg-color);
}

.upload-area p { margin: 0 0 0.5rem 0; font-size: 1.1rem; }
.upload-area span { color: var(--text-color-tertiary); font-size: 0.9rem; }
input[type="file"] { display: none; }
#thumbnails-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 1rem; margin-top: 1rem; }
.thumbnail-wrapper { position: relative; padding-top: 100%; border-radius: 8px; overflow: hidden; background: var(--input-bg-color); }
.thumbnail-wrapper img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.thumbnail-wrapper .remove-btn { position: absolute; top: 5px; right: 5px; background: rgba(0, 0, 0, 0.5); border: none; color: white; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; padding: 0; line-height: 1; }


textarea, input[type="password"], input[type="number"], select {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--input-bg-color);
    color: var(--text-color-primary);
    box-sizing: border-box;
    font-family: inherit;
    font-size: 1rem;
    transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}

textarea { min-height: 100px; resize: vertical; }

select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1.2em;
    padding-right: 2.5rem;
}

.light-mode select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
}


.count-buttons-container { display: flex; width: 100%; }
.count-btn { flex: 1; padding: 10px; background-color: var(--input-hover-bg-color); border: 1px solid var(--border-color); color: var(--text-color-secondary); cursor: pointer; transition: background-color 0.3s, color 0.3s, border-color 0.3s; }
.count-btn:first-child { border-radius: 8px 0 0 8px; }
.count-btn:last-child { border-radius: 0 8px 8px 0; }
.count-btn:not(:last-child) { border-right: none; }
.count-btn:hover { background-color: var(--input-bg-color); }
.count-btn.active { background: linear-gradient(90deg, var(--gradient-mid), var(--gradient-end)); color: white; border-color: var(--gradient-mid); }

.error-message { color: var(--error-color); font-size: 0.85rem; margin-top: 0.5rem; min-height: 1.2em; }
.input-error { border-color: var(--error-color) !important; }

.generate-btn {
    background: linear-gradient(90deg, var(--gradient-mid), var(--gradient-end));
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.2s ease, opacity 0.2s ease;
    margin-top: auto;
}

.generate-btn:not(:disabled):hover { transform: translateY(-2px); }
.generate-btn:disabled { opacity: 0.7; cursor: not-allowed; }

.spinner { width: 20px; height: 20px; border: 2px solid transparent; border-top-color: #ffffff; border-radius: 50%; animation: spin 1s linear infinite; }
.hidden { display: none !important; }

#main-result-image { flex: 1; background-color: var(--input-bg-color); border-radius: 8px; padding: 1rem; display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 400px; max-height: 70vh; margin-bottom: 1rem; transition: background-color 0.3s; }
#main-result-image img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: pointer; border-radius: 8px; }
#main-result-image p { color: var(--text-color-tertiary); text-align: center; }
#main-result-image pre { max-width: 100%; white-space: pre-wrap; word-wrap: break-word; font-family: inherit; }
#result-thumbnails { display: flex; gap: 1rem; justify-content: center; align-items: center; height: 100px; }
.result-thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 3px solid transparent; transition: border-color 0.3s ease; }
.result-thumb:hover { border-color: var(--text-color-tertiary); }
.result-thumb.active { border-color: var(--gradient-mid); }
.loading-spinner { width: 50px; height: 50px; border: 5px solid var(--border-color); border-top-color: var(--gradient-mid); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 1rem; }

@keyframes spin { to { transform: rotate(360deg); } }

/* 全屏 Modal 样式 */
#fullscreen-modal { position: fixed; z-index: 9999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.95); display: flex; justify-content: center; align-items: center; }
#modal-image { max-width: 90%; max-height: 90%; display: block; object-fit: contain; }
.close-btn { position: absolute; top: 20px; right: 35px; color: #fff; font-size: 40px; font-weight: bold; transition: 0.3s; cursor: pointer; }

@media (max-width: 1024px) {
    #main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem;
    }
    #sidebar {
        box-shadow: 0 0 40px rgba(0,0,0,0.2);
    }
    .main-container {
        flex-direction: column;
    }
    #theme-toggle-btn { top: 1rem; right: 1rem; }
    #sidebar-toggle-btn { top: 1rem; left: 1rem; }
    .title { margin-top: 4rem; }
}

/* 新增的样式 */
.upload-section {
    margin-bottom: 1.2rem;
}

.upload-section.hidden, .settings-section.hidden, .count-selector.hidden {
    display: none !important;
}
